import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import { createVNode as _createVNode } from "vue";
import { computed, defineComponent } from 'vue';
import { presetPrimaryColors } from '@ant-design/colors';
import { Circle as VCCircle } from '../vc-progress';
import { getSuccessPercent, validProgress } from './utils';
import { progressProps } from './props';

function getPercentage(_ref) {
  var percent = _ref.percent,
      success = _ref.success,
      successPercent = _ref.successPercent;
  var realSuccessPercent = validProgress(getSuccessPercent({
    success: success,
    successPercent: successPercent
  }));
  return [realSuccessPercent, validProgress(validProgress(percent) - realSuccessPercent)];
}

export default defineComponent({
  inheritAttrs: false,
  props: progressProps(),
  setup: function setup(props, _ref2) {
    var slots = _ref2.slots;
    var gapDeg = computed(function () {
      // Support gapDeg = 0 when type = 'dashboard'
      if (props.gapDegree || props.gapDegree === 0) {
        return props.gapDegree;
      }

      if (props.type === 'dashboard') {
        return 75;
      }

      return undefined;
    });
    var circleStyle = computed(function () {
      var circleSize = props.width || 120;
      return {
        width: typeof circleSize === 'number' ? "".concat(circleSize, "px") : circleSize,
        height: typeof circleSize === 'number' ? "".concat(circleSize, "px") : circleSize,
        fontSize: "".concat(circleSize * 0.15 + 6, "px")
      };
    });
    var circleWidth = computed(function () {
      return props.strokeWidth || 6;
    });
    var gapPos = computed(function () {
      return props.gapPosition || props.type === 'dashboard' && 'bottom' || 'top';
    }); // using className to style stroke color

    var strokeColor = computed(function () {
      return [presetPrimaryColors.green, props.strokeColor || null];
    });
    var percent = computed(function () {
      return getPercentage(props);
    });
    var isGradient = computed(function () {
      return Object.prototype.toString.call(props.strokeColor) === '[object Object]';
    });
    var wrapperClassName = computed(function () {
      var _ref3;

      return _ref3 = {}, _defineProperty(_ref3, "".concat(props.prefixCls, "-inner"), true), _defineProperty(_ref3, "".concat(props.prefixCls, "-circle-gradient"), isGradient.value), _ref3;
    });
    return function () {
      var _a;

      return _createVNode("div", {
        "class": wrapperClassName.value,
        "style": circleStyle.value
      }, [_createVNode(VCCircle, {
        "percent": percent.value,
        "strokeWidth": circleWidth.value,
        "trailWidth": circleWidth.value,
        "strokeColor": strokeColor.value,
        "strokeLinecap": props.strokeLinecap,
        "trailColor": props.trailColor,
        "prefixCls": props.prefixCls,
        "gapDegree": gapDeg.value,
        "gapPosition": gapPos.value
      }, null), (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)]);
    };
  }
});